<?php
require_once $_SERVER["DOCUMENT_ROOT"] . "/config/globalconfig.php";
require_once $_SERVER["DOCUMENT_ROOT"] . "/public/Information.php";
require_once $_SERVER["DOCUMENT_ROOT"] . "/public/Attachment.php";
$information = new Information();
$information->loginCheck();
$attach = new Attachment();
$action = $_REQUEST["action"];
$condition = array();
//$data = array();
$reda;
$message = "success";
$code = 200;
try {
    switch ($action) {
        case LOAD:
            $reda = $information->findOne();
            break;
        case LOAD_ID:
            $condition[$information->getPrimaryKey()] = $_GET["id"];
            $reda = $information->findOne($condition);
            break;
        case "logo":
        case "webchat":
            $reda = $attach->uploadWithoutSave($action, "system",$action);
            break;
        case ALL:
            $reda = $information->findList();
            break;
        case PAGE:
            $page = $_REQUEST["currentPage"];
            $pageSize = $_REQUEST["pageSize"];
            $condition = $information->searchData();
            $reda = $information->findByPage($page, $pageSize, $condition);
            break;
        case DELETE:
            $ids = $_POST["ids"];
            $condition[$information->getPrimaryKey()] = [$information->param_operation => "in", $information->param_value_key => $ids];
            $reda = $information->delete($condition);
            break;
        case MERGE:
            $data = $information->parseRequestData();
            $reda = $information->merge($information->getPrimaryKey(), $data);
            break;
        case "backup":
            $information->backup($_GET["type"]);
            break;
        case "loaddb":
            $reda = $information->loadDbFile();
            break;
        case "restore":
            $information->restore($_GET["fileName"], $_GET["type"]);
            break;
        case "html":
            $information->html($_GET["type"]);
            break;
        default:
            $reda = "未知Action";
    }
    $information->result($reda, $message, $code);
} catch (Exception $e) {
    $information->result($e->getMessage(), $information->error_msg, $information->error_code);
}


?>
